<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>机构用户管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <link rel="stylesheet" href="${ctx}/css/ui/system/member/member_list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/crowdfund/analyze_list.css">
    <%@include file="../../include/commonFile.jsp" %>
    <style type="text/css">
        .layui-table[lay-size=sm] td, .layui-table[lay-size=sm] th {
            padding: 5px !important;
        }
    </style>
</head><body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">

            <form class="layui-form" action="${ctx}/member/group/memberList.do" id="myForm" method="post">
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="realname" autocomplete="off" class="layui-input" placeholder="请输入查询昵称">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">用户名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="username" autocomplete="off" class="layui-input" placeholder="请输入查询用户名">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">手机号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="mobile" autocomplete="off" class="layui-input" placeholder="请输入查询手机号">
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item">
                                <label class="search-form-lable">用户身份</label>
                                <div class="check-btn-inner">
                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'')" class="active">全部</a>
                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'userStatus:2')">实名</a>
                                    <%--<a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'userStatus:1')">认证</a>--%>
<%--                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isExpert:1')">达人</a>--%>
                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isPartner:1')">合作商</a>
<%--                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isDistributor:1')">分销商</a>--%>
<%--                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isCopartner:1')">联合发起人</a>--%>
                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isCosponsor:1')">合作渠道</a>
                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isXzgs:1')">行知公社</a>
<%--                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isChannelDis:1')">合伙人</a>--%>
                                    <a href="javascript:void(0);" onclick="mainApp.setMemberType($(this),'isAdmin:1')">管理员</a>
                                    <input type="hidden" name="memberType" value="${memberType}"/>
                                </div>
                                <div class="cl"></div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger" href="javascript:mainApp.reloadTable()">查询</a>
                                    <a class="layui-btn layui-btn-normal" href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">

                            <li class="form-item"><label class="search-form-lable">注册时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a href="javascript:void(0);" onclick="mainApp.setTimeType($(this),0)" class="active">全部</a>
                                    <a href="javascript:void(0);" onclick="mainApp.setTimeType($(this),1)">今天</a>
                                    <a href="javascript:void(0);" onclick="mainApp.setTimeType($(this),2)">本周内</a>
                                    <a href="javascript:void(0);" onclick="mainApp.setTimeType($(this),3)">本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <div class="cl">
                    <table id="order_table" class="analyze-table" lay-filter="member_table"></table>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
</div>

<script type="text/html" id="identityHtml">
    <div>
        <span class="red">
            {{# if(d.isXzgs == 1){ }} 行知公社 {{# } }}
            {{# if(d.isExpert == 1){ }} 达人 {{# } }}
            {{# if(d.isPartner == 1){ }} 合作商 {{# } }}
            {{# if(d.isAdmin == 1){ }} 管理员 {{# } }}
            {{# if(d.isDistributor == 1){ }} 分销商 {{# } }}
            {{# if(d.isCosponsor == 1){ }} 合作渠道 {{# } }}
            {{# if(d.isChannelDis == 1){ }} 合伙人 {{# } }}
            {{# if(d.isCopartner == 1 && d.type == 1){ }} 联合发起人 {{# } }}
            {{# if(d.isCopartner == 1 && d.type == 2){ }} 联合发起机构 {{# } }}
        </span>
        {{# if(!(d.isPartner == 1 || d.isAdmin == 1 || d.isDistributor == 1 || d.isCosponsor == 1 || d.isChannelDis == 1 || d.isCopartner == 1 || d.isExpert == 1)){ }} 普通人 {{# } }}
    </div>
</script>
<script type="text/html" id="optHtml">
    <a href="javascript:openDialog('解绑授权账户','${ctx}/system/member/getAuthList.do?memberId={{ d.id }}&type=0','500px','400px')">解绑授权</a>
    | <a href="${ctx}/log/event/behaviorList.do?operatorId={{ d.id }}">行为分析</a>
    {{# if(util.isValid(d.username) && util.isValid(d.mobile)){ }}
    | <a href="javascript:unbindPhone('{{ d.id }}')">解绑手机</a>
    {{# } }}
    {{# if(d.isPartner != 1 && d.isAdmin != 1 && !util.isValid(d.partnerId)){ }}
        <%--| <a href="${ctx}/system/member/memberForm.do?id={{ d.id }}" target="_self">
            编辑
        </a>--%>
        | <a target="_self"
           href="javascript:openDialog('分配角色','${ctx}/system/role/distributionRole.do?memberId={{ d.id }}&identity=normal&type={{ d.type }}&isNew=true','650px','450px')">
            分配角色
        </a>
    {{# } }}
    {{# if(d.isPartner == 1 || d.isCopartner == 1 || d.isCosponsor == 1 || d.isChannelDis == 1 || d.isAdmin == 1){ }}
        | <a href="${ctx}/system/member/resetPwdForm.do?memberId={{ d.id }}&isGroup=1" target="_self">修改密码</a>
    {{# } }}
</script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    var laytpl, laypage, element, laytable, analyzeT, mainApp, loadingIndex, layfrom, laydate;
    $(function () {
        layui.use(['laytpl', 'laypage', 'element', 'table', 'form', 'laydate'], function () {
            laytpl = layui.laytpl;
            laypage = layui.laypage;
            element = layui.element;
            laytable = layui.table;
            layfrom = layui.form;
            laydate = layui.laydate;

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);


            var opts = {
                id: 'order_table',
                elem: '#order_table',
                url: '${ctx}/member/group/api/list.do',
                method: 'post',
                where: {
                    realname: '',
                    username: '',
                    mobile: '',
                    title: '',
                    memberName: '',
                    initiatorName: '',
                    paymentWay: '',
                    status: '',
                    tradeStatus: '',
                    timeType: '',
                    createStart: '',
                    createEnd: '',
                    type: ''
                },
                request: {
                    pageName: 'pageNo', //页码的参数名称，默认：page
                    limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                limit: '20',
                skin: '1',
                page: {
                    theme: '#e8473f'
                },
                even: true, //开启隔行背景
                size: 'sm', //小尺寸的表格
                height: 'full-250',
                // cellMinWidth: 100,
                done: function () {
                    layer.close(loadingIndex);
                },
                cols: [[
                    {
                        field: 'realname',
                        title: '昵称',
                        width: '15%',
                        templet: '<div><div class="member-cell" onclick="openDialogShow(\'用户名片\',\'${ctx}/system/member/memberView.do?id={{d.id}}\',\'400px\',\'470px\')">\n' +
                            '     <img class="member-logo-img" src="{{ d.logo }}?imageMogr2/auto-orient/crop/126x126" onerror=null;src=\'${ctx}/image/def_user_logo.png\' />' +
                            '     <div class="member-name ellipsis-1">' +
                            '       <a title="{{d.realname || \'\'}}" href="javascript:void(0);">{{d.realname || \'\'}}</a>\n' +
                            '     </div>\n' +
                            ' </div></div>'
                    },
                    {
                        field: 'username', title: '用户名', width: '10%'
                    },
                    {
                        field: 'mobile', title: '手机号', width: '10%'
                    },
                    {
                        field: 'wechatNum', title: '微信号', width: '10%'
                    },
                    {
                        field: 'identity',
                        title: '身份',
                        width: '15%',
                        templet: '#identityHtml'
                    },
                    {
                        field: 'memberType', title: '类型', width: '5%',
                        templet: '<div><div class = "red">' +
                            '{{# if(d.type == 1){ }} 个人 {{# } }}' +
                            '{{# if(d.type == 2){ }} 机构 {{# } }}' +
                            '{{# if(d.type == 3){ }} 平台 {{# } }}' +
                            '</div></div>'
                    },
                    {
                        field: 'createDate', title: '注册时间', width: '8%',
                        templet: '<div><div title="{{util.getDateStr(d.createDate).Format(\'yyyy-MM-dd HH:mm:ss\')}}">{{util.getDateStr(d.createDate).Format(\'yyyy-MM-dd HH:mm:ss\')}}</div></div>'
                    },
                    /*{
                        field: 'status', title: '状态', width: '6.5%',
                        templet: '<div><div class = "red">' +
                            '{{# if(d.userStatus == 0 || d.userStatus == 2 || d.userStatus == 3){ }} 未认证 {{# } }}' +
                            '{{# if(d.userStatus == 1){ }} 已认证 {{# } }}' +
                            '</div></div>'
                    },*/
                    {
                        field: 'option', title: '操作',
                        templet: '#optHtml'
                    }
                ]]
            }

            analyzeT = laytable.render(opts);
        });


        mainApp = {
            reloadTable: function () {
                loadingIndex = layer.load(1);
                var formData = util.serializeForm($('#myForm').serializeArray());
                analyzeT.reload({
                    where: formData,
                    page: {
                        theme: '#e8473f',
                        curr: 1 //重新从第 1 页开始
                    }
                });
            },
            setMemberType: function (o, value) {
                $('input[name=memberType]').val(value);
                $(o).parent(".check-btn-inner").find("a").removeClass("active");
                $(o).addClass('active');
                mainApp.reloadTable();
            },
            setTimeType: function (o, value) {
                $('input[name=timeType]').val(value);
                $(o).parent(".check-btn-inner").find("a").removeClass("active");
                $(o).addClass('active');
                mainApp.reloadTable();
            },
        }
    });

    function openDialog(title, url, width, height, target) {
        layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }

            },
            cancel: function (index) {
            }
        });
    }

    /**
     * 解绑手机
     * @param memberId 用户id
     */
    function unbindPhone(memberId, username) {
        layer.confirm("确定要解绑该用户的手机号码吗？", {icon: 3, title: '系统提示：该功能慎用'}, function (index) {
            $.post('${ctx}/member/group/unbindPhone.do', {memberId: memberId}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess('解绑成功', function () {
                        submitFunction('#myForm')
                    });
                } else {
                    util.layerMsgError('解绑失败');
                }
            })
        });
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '机构用户管理',
            curr: true
        }],
        info:'',
        btns:[
            <%--{--%>
                <%--name: '添加用户',--%>
                <%--href: '${ctx}/system/member/memberForm.do',--%>
                <%--icon: 'add'--%>
            <%--}--%>
        ]
    });
</script>
</body>
</html>